package visiopuce.DAO;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.Query;

import visiopuce.HibernateUtil;
import visiopuce.objets.ControleQualite;
import visiopuce.objets.Puce;

public class ControleQualiteDAOImpl extends GenericDAOImpl<ControleQualite, BigDecimal> implements ControleQualiteDAO {

	/** Constructeur priv� */
	private ControleQualiteDAOImpl() {
	}

	/** Instance unique non pr�initialis�e */
	private static ControleQualiteDAOImpl INSTANCE = null;

	/** Point d'acc�s pour l'instance unique du singleton */
	public static ControleQualiteDAO getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new ControleQualiteDAOImpl();
		}
		return INSTANCE;
	}

	@Override
	public ControleQualite getQCByPuceTypeQc(Puce puce, String libelleTypeQc) {
		ControleQualite qc = null;
		List<ControleQualite> qcs = null;
		String sql = "SELECT d FROM ControleQualite d WHERE d.puce.idPuce = :idPuce AND d.typeQC.libelle LIKE :libelle";
		Query query = HibernateUtil.getSession().createQuery(sql).setParameter("idPuce", puce.getIdPuce()).setParameter("libelle", libelleTypeQc);
		qcs = findMany(query);
		if (qcs.size() > 0) {
			qc = qcs.get(0);
		}
		return qc;
	}

}